<style>
    .layui-form-item .layui-inline {
        margin-top: 10px;
    }
</style>
<div class="layui-fluid" id="Ship-create">
    <div class="layui-card">
        <div class="layui-form" lay-filter="LAY-list-form">
            <div id="view"></div>
        </div>
    </div>
</div>
<script id="page1" type="text/html">
    <input type="hidden" name="id" value="{{layui.router().search.id||''}}">
    <div class="layui-card-header">销项单资料</div>
    <div class="layui-card-body">
        <div class="layui-form-item">
            {{# if(layui.router().search.id>0){ }}
            <div class="layui-inline">
                <label class="layui-form-label">销项单号:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.result.code||''}}</span>
                </div>
            </div>
            {{# } }}
            {{# if(d.result.bs_code){ }}
            <div class="layui-inline">
                <label class="layui-form-label">业务单号单号:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.result.bs_code||''}}</span>
                </div>
            </div>
            {{# } }}
            <div class="layui-inline">
                <label class="layui-form-label">销售公司:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{ d.info.company[d.result.supplier_company_id] }}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">发货仓库:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{ d.info.warehouse[d.result.ship_warehouse_id]||'' }}</span>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">客户名称:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{ d.info.company[d.result.purchase_company_id]||'' }}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label layui-label-jy">客户地址:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{ d.result.purchase_addr }}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">销项金额:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.result.money||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">销项时间:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.result.ctime||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">创建人员:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.result.user||''}}</span>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-card-header">商品信息</div>
    <div class="layui-card-body">

        <div class="layui-item">
            <button class="export1 layui-btn">导出</button>
        </div>
        <table id="LAY-list" lay-filter="LAY-list"></table>

    </div>

    <div class="layui-card-body layui-jy-center">
        <a lay-href="Sell/index" class="layui-btn">返回</a>
        {{# if(!layui.router().search.id) { }}
        <input type="button" lay-submit lay-filter="LAY-submit-1" value="保存" class="layui-btn LAY-submit1">
        {{#} }}
    </div>

</script>
<!-- 行内工具 -->
<script type="text/html" id="LAY-list-toolbar">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="del" href="javascript:;">删除</a>
</script>
<script>
    layui.use(['admin', 'form', 'toolJ', 'laytpl', 'laydate', 'upload', 'table'], function () {
        var $ = layui.$
            , form = layui.form
            , laytpl = layui.laytpl
            , setter = layui.setter
            , laydate = layui.laydate
            , table = layui.table
            , toolJ = layui.toolJ;
        var id = layui.router().search.id;

        //导出
        $("body").off('click.export1').on('click.export1', '.export1', function () {
            $(".layui-table-tool .layui-inline[lay-event='LAYTABLE_EXPORT']").click();
            $(".layui-table-tool li[data-type='csv']").click();
        })

        //详情
        function tableView2(data) {
            table.render({
                elem: '#LAY-list'
                , data: data
                , toolbar: true
                , defaultToolbar: ['exports', 'filter', 'print']
                , cellMinWidth: 80
                , cols: [[
                    {field: 'sku', title: 'sku'}
                    , {field: 'sku_name', title: '采购名称'}
                    , {field: 'quantity', title: '采购数量'}
                    , {field: 'unit_price', title: '单价'}
                    , {field: 'money', title: '金额'}
                ]]
                , page: false
                , limit: 100000
                , text: '加载出现异常！'
            });
        }

        function viewHtml(data) {
            var getTpl = page1.innerHTML
                , view = $('#view');
            laytpl(getTpl).render(data, function (html) {
                view.html(html);
            });
            if (data.type == 1) {
                tableView2(data.detail);
            }
            table.render(null, 'LAY-list');
            form.render(null, 'LAY-list-form');
        }

        var info = {};
        info.shop = layui.data(setter.tableName).shop;
        info.warehouse = layui.data(setter.tableName).warehouse;
        info.company = layui.data(setter.tableName).company;
        if (id) {
            toolJ.ajax({"data": {"id": id}, "type": "get"},
                function (data) {
                    viewHtml({"info": info, "result": data.data.result, "type": 1, "detail": data.data.detail});
                }
            );
        }


    })
</script>